import { ApiProperty } from '@midwayjs/swagger';
import { Rule, RuleType } from '@midwayjs/validate';
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
export class LeaveBill {
  applier: string;
  reason: string;
  leaveTime: number;
  //   constructor(applier: string, reason: string, leaveTime: number) {
  //     this.applier = applier;
  //     this.reason = reason;
  //     this.leaveTime = leaveTime;
  //   }
}
// 病假 年假 事假
// 枚举使用字符串类型 对程序员友好，方便初始开发
// 枚举使用数字类型 对数据库性能友好，适合查询和group分组
export enum LeaveType {
  sick = 'sick',
  annual = 'annual',
  issue = 'issue',
}
// Object.values(LeaveType)
@Entity({
  name: 'LeavePage',
  synchronize: false,
})
export class LeavePage {
  @ApiProperty({ example: 0 })
  @Rule(RuleType.number().required())
  @PrimaryGeneratedColumn()
  id: number;
  @ApiProperty({ example: 'zhangsan' })
  @Rule(RuleType.string().required())
  @Column()
  applier: string;
  @ApiProperty({ example: LeaveType.sick })
  @Rule(
    RuleType.string()
      .valid(...Object.values(LeaveType))
      .required()
  )
  @Column({
    type: 'enum',
    enum: LeaveType,
    default: LeaveType.sick,
  })
  // @Rule(RuleType.string().valid('sick', 'annual', 'issue').required())
  // ['sick', 'annual', 'issue']
  leaveType: LeaveType;
}
